package com.lcj.eduService.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcj.commonutils.R;
import com.lcj.eduService.entity.EduCourse;
import com.lcj.eduService.entity.chapter.ChapterVo;
import com.lcj.eduService.entity.front.CourseWebVo;
import com.lcj.eduService.entity.vo.CourseFrontVo;
import com.lcj.eduService.entity.vo.CourseInfoVo;
import com.lcj.eduService.service.EduChapterService;
import com.lcj.eduService.service.EduCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author：LCJ
 * @Description：
 * @Date：Create in 21:12 2021/3/24 0024
 */
@RestController
@CrossOrigin
@RequestMapping("eduservice/courseFront")
public class CourseFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduChapterService eduChapterService;


    //条件查询分页查询
    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseInfo(@PathVariable long page,
                                @PathVariable long limit,
                                @RequestBody(required = false)CourseFrontVo courseFrontVo){
        Page<EduCourse> pageCourse = new Page<>();
        Map<String,Object> map =courseService.getCourseFrontList(pageCourse,courseFrontVo);
        return R.ok().data(map);
    }

    @GetMapping("getFrontCourseInfo/{id}")
    public R getFrontCourseInfo(@PathVariable String id){
        //根据课程id查询所有,编写sql查询课程信息
        CourseWebVo courseWebVo = courseService.getBaseCourseInfo(id);

        //根据课程id查询章节和小节
        List<ChapterVo> chapterVos = eduChapterService.getChapterVideoByCourseId(id);
        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVos);
    }
}
